﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Gunningine
{
    public class GameStateLoad : GameState
    {
        private bool resourcesLoaded = false;

        public bool ResourcesLoaded
        {
            get { return this.resourcesLoaded; }
        }

        /// <summary>
        /// Constructor.
        /// </summary>
        public GameStateLoad() :
            base("Load")
        {
        }

        #region GameState implementation

        /// <summary>
        /// Callback for when everything is loaded.
        /// </summary>
        private void OnLoaded()
        {
            this.renderSystem.CreateShader("EntityShader", "Shaders/KeyframeAnimVS", "Shaders/TargetedFS");
            this.renderSystem.CreateShader("WorldShader", "Shaders/PassThroughVS", "Shaders/TargetedFS");

            this.resourcesLoaded = true;
        }

        /// <summary>
        /// Callback for progress in loading.
        /// </summary>
        /// <param name="percent"></param>
        private void OnProgress(float percent)
        {
        }

        /// <summary>
        /// Enter this state.
        /// </summary>
        /// <param name="prevState">the previous game state (which we are exiting from).</param>
        protected override void EnterImpl(GameState prevState)
        {
            // Start loading resources into memory.  We should prioritise things that are
            // needed for this state, so it can start using them as soon as possible.
            //this.resourceMgr.BeginLoadAllResources(this.renderSystem, this.bulletMachine, OnLoaded, OnProgress);
            this.resourceMgr.LoadAllResources(this.renderSystem, this.scriptMgr);
            OnLoaded();
        }

        /// <summary>
        /// Exit this state.
        /// </summary>
        protected override void ExitImpl()
        {
            // Clean up resources from memory (forcibly).
        }

        /// <summary>
        /// Render the state.
        /// </summary>
        /// <param name="renderSystem">render system to use for rendering.</param>
        protected override void RenderImpl(RenderSystem renderSystem)
        {
            // At this point, the render system is initialised, however not all
            // resources will have been loaded.  So this render function must not
            // use any resources (eg images) until we know they are loaded - this
            // includes fonts.

            // So use bootstrapped resources, which will be in a different directory.
        }

        #endregion
    }
}
